<?php

use Illuminate\Http\Request;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request as GRequest;
use GuzzleHttp\Psr7\Response;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    $u = $request->user();
    $res = ['emp_id'=>$u->employee->id,'email'=>$u->email,'name'=>$u->employee->name,'department'=>$u->employee->department->name];
    return $res;
});

Route::get("/departments","DepartmentController@getAll");
Route::post("/departments","DepartmentController@create");
Route::get("/departments/{id}","DepartmentController@getOne");
Route::put("/departments/{id}","DepartmentController@modify");
Route::delete("/departments/{id}","DepartmentController@delete");

//Route::get("/employees","EmployeeController@getAll");
Route::get("/employees","EmployeeController@getPageData");
Route::get("/employee/positions","EmployeeController@getPositions");
Route::get("/employee/titles","EmployeeController@getTitles");

Route::post("/login",function(Request $req){
    $data = [
        "client_id"=>2,
        "client_secret"=>"HJRv9WQWnKQVsXxf51hmGFeEuVmRVM2BkDeXL9Kx",
        "grant_type" => "password",
        "username" => $req->username,
        "password" => $req->password,
    ];

    $req->request->add($data);
    $proxy = Request::create('/oauth/token', 'POST');
    return Route::dispatch($proxy);
});
